//
//  back.m
//  stock
//
//  Created by Yangfan on 15/3/9.
//  Copyright (c) 2015年 4gread. All rights reserved.
//

#import "back.h"

@implementation back

// 获取当前上证或者深证的指数通过接口
- (void)currentZhiShu {
    //    数据含义分别为：指数名称，当前点数，当前价格，涨跌率，成交量（手），成交额（万元）；
    NSStringEncoding enc =CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
    //
    NSString *str;
    if (shanghaiOrShenzheng) {
        str = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://hq.sinajs.cn/list=s_sz399001"] encoding:enc error:nil];
    } else {
        str = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://hq.sinajs.cn/list=s_sh000001"] encoding:enc error:nil];
    }
    //    str = @"var hq_str_s_sh000001='上证指数,3094.668,-128.073,-3.97,436653,5458126';";
    NSString *parten = @"[\\,]{1}[\\-]{0,1}[\\d]{1,}[\\.]{0,1}[\\d]{0,}";
    NSError* error = NULL;
    NSRegularExpression *reg = [NSRegularExpression regularExpressionWithPattern:parten options:NSRegularExpressionCaseInsensitive error:&error];
    NSArray* match = [reg matchesInString:str options:NSMatchingReportProgress range:NSMakeRange(0, [str length])];
    if (shanghaiShenzhengZhiShuOrArr != nil) {
        [shanghaiShenzhengZhiShuOrArr removeAllObjects];
    } else {
        shanghaiShenzhengZhiShuOrArr = [[NSMutableArray alloc] init];
    }
    if (match.count != 0) {
        for (NSTextCheckingResult *matc in match) {
            NSRange range = [matc range];
            range = NSMakeRange(range.location + 1, range.length - 1);
            [shanghaiShenzhengZhiShuOrArr addObject:[str substringWithRange:range]];
        }
    }
    NSLog(@"****%@", shanghaiShenzhengZhiShuOrArr);
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
